package com.example.petproject.controller;

import com.example.petproject.entity.dto.CommentListDTO;
import com.example.petproject.entity.dto.PostCommentDTO;
import com.example.petproject.entity.vo.CommentListVO;
import com.example.petproject.entity.vo.PageResult;
import com.example.petproject.entity.vo.ReturnVO;
import com.example.petproject.service.PmsCommentService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 包名称：com.example.petproject.controller
 * 类名称：PmsCommentController
 * 类描述：商品评价控制器
 * 创建人：@author DrinkMore-HotWater
 * 创建时间：2024年01月10日 11:00
 **/
@RestController
@RequestMapping("pms/comment")
@Tag(name = "商品评价接口")
public class PmsCommentController {
    private static final Logger log = LoggerFactory.getLogger(PmsCommentController.class);


    @Resource
    private PmsCommentService pmsCommentService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private ObjectMapper objectMapper;

    /**
     *
     * @return ReturnVO<?>
     */
    @Operation(summary = "发表评论")
    @PostMapping("/postComment")
    private ReturnVO<?> postComment(@RequestHeader("Token") String token,PostCommentDTO postCommentDTO){
        pmsCommentService.postComment(token,postCommentDTO);
        log.info("token: {}", token);
        log.info("postCommentDTO: {}", postCommentDTO);
        return ReturnVO.ok();
    }

    /**
     * @param commentListDTO 参数
     * @return PageResult<List<CommentListVO>>
     */
    @Operation(summary = "查询评论列表")
    @GetMapping("/commentList")
    public ReturnVO<PageResult<CommentListVO>> getCommentList(CommentListDTO commentListDTO) {
        //分页
        PageHelper.startPage(commentListDTO.getPageNo(), 20);
        PageResult<CommentListVO> commentList = pmsCommentService.getCommentList(commentListDTO);
        return ReturnVO.ok(commentList);
    }

}
